﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;

namespace Btrieve_Retriever
{
    public partial class Form2 : Form
    {
        String tableName;
        public Form2(String title)
        {
            InitializeComponent();
            this.Text = title;
            tableName = title;
            populateTable();
        }

        private void populateTable() {
            String query = "SELECT * FROM " + tableName;
            OdbcCommand command = new OdbcCommand(query, Program.myConnection);
            Console.WriteLine("1");
          
            OdbcDataAdapter adapter = new OdbcDataAdapter(query, Program.myConnection);

            DataTable table = new DataTable();
            adapter.Fill(table);
            Console.WriteLine("2");
            table.DefaultView.AllowDelete = false;
            table.DefaultView.AllowEdit = false;
            table.DefaultView.AllowNew = false;
            table.Locale = System.Globalization.CultureInfo.InvariantCulture; 
          //  bindingSource1.DataSource = table;
            dataGridView1.DataSource = table.DefaultView;
            Console.WriteLine("3");
            if (table.Rows.Count > 0) {
                Console.WriteLine("FEE TABLE");
            }
            if (dataGridView1.RowCount > 0) {
                Console.WriteLine("FEE Grid");
            }

          

            //Console.WriteLine(dataGridView1.Rows[0].Cells[0].ToString());
           /* OdbcDataReader reader = command.ExecuteReader();
            reader.Read();
            Console.WriteLine("COLUMNS: " + reader.FieldCount);*/
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet4.AUKUN1' table. You can move, or remove it, as needed.
           if(tableName.Equals("AUKUN1")){
               Console.WriteLine("AUKUN1 form load");
               this.aUKUN1TableAdapter1.Fill(this.dataSet4.AUKUN1);
           }
           if (tableName.Equals("MASKENCODE"))
           {
               this.mASKENCODETableAdapter.Fill(this.dataSet4.MASKENCODE);
           }
           if (tableName.Equals("TAUKU2"))
           {
               this.tAUKU2TableAdapter.Fill(this.dataSet4.TAUKU2);
           }
           if (tableName.Equals("TTMPOS"))
           {
               this.tTMPOSTableAdapter.Fill(this.dataSet4.TTMPOS);
           }
           if (tableName.Equals("TTSTDAT"))
           {
               this.tTSTDATTableAdapter.Fill(this.dataSet4.TTSTDAT);
           }
            
           // dataGridView1.DataSource = table;
        }

        private void Form2_FormClosed(object sender, FormClosedEventArgs e)
        {
          //  Application.Exit();
        }

        private void bindingSource1_DataSourceChanged(object sender, EventArgs e)
        {
            Console.WriteLine("DATA SOURCE CHANGE:");
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

     
    }
}
